<h1 class="layui-inline">个人主页</h1>
<hr class="layui-bg-black">
<table id="tb_users" class="layui-table" lay-filter="users">
</table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">修改信息</a>
</script>
<script>

    layui.use(function () {
        var $=layui.$;
        var table = layui.table;
        table.render({
            elem: '#tb_users',
            url: "/main/user_list",
            id: 'idTest',
            cols: [[
                {field: 'account',width: 100, sort: true, title: '账号'},
                {field: 'password',width: 100, sort: true, title: '密码'},
                {field: 'showName',width: 100, sort: true, title: '昵称'},
                {field: 'tel', sort: true, title: '电话号码'},
                {field: 'sex',width: 80, sort: true, title: '性别'},
                {field: 'age',width: 100, sort: true, title: '年龄'},
                {field: 'addr', sort: true, title: '地址'},
                {field: 'email', sort: true, title: '邮箱'},
                {field: 'wechat', sort: true, title: '微信号'},
                {fixed: 'right', width: 180, align: 'center', title: '操作', toolbar: '#barDemo'}
            ]]
        });
        //监听工具条
        table.on('tool(users)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                layer.prompt({
                    title: '个人信息修改',
                    formType: 2,
                    value: data,
                }, function (value, index) {
                    var load = layer.load(1, {shade: 0.3});

                    $.get("/main/user_list",function (result) {
                        $.each(result, function (index, item) {
                            $("#user_auths").append(tem.replace("[[id]]", item.id).replace("[[title]]", item.title));
                        });
                        $.each(data, function (index, item) {
                            $("#user_auths input[value=" + item.id + "]").attr("checked", "");
                        });
                        form.render();
                    });

                    $.get("/main/user_list_edit", {id: data.id, data:value}, function (data) {
                        layer.close(load);
                        if (data.code == 1) {
                            layui.table.reload('idTest');
                            layer.msg("修改成功!", {icon: 1});
                        } else {
                            layer.msg(data.msg, {icon: 2});
                        }
                    });
                    layer.close(index);
                });
            }
        });

    });
</script>